package day07;
/**
 * 需求:
 * <<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
 * 选手的最后得分为：去掉最高分、最低分后的4个评委的平均分
 */

import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {
        double[] scores = enterData();
        double avg = calAvg(scores);
        System.out.println("平均分为:" + avg);
    }

    //录入成绩
    public static double[] enterData() {
        Scanner sc = new Scanner(System.in);
        double[] scores = new double[6];
        for (int i = 0; i < scores.length; i++) {
            while (true) {
                System.out.println("请录入第" + (i + 1) + "个评委的分数:");
                scores[i] = sc.nextDouble();
                if (scores[i] < 0 || scores[i] > 100) {
                    System.out.println("录入成绩不合法,请重新录入");
                    continue;
                }
                break;
            }
        }
        return scores;
    }

    //去掉最高分和最低分
    public static double calTotal(double[] scores) {
        double sum = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            if (max < scores[i]) {
                max = scores[i];
            }
            if (min > scores[i]) {
                min = scores[i];
            }
            sum += scores[i];
        }
        return sum - max - min; //去掉最高分和最低分
    }

    public static double calAvg(double[] scores) {
        double sum = calTotal(scores); //获取总分
        double avg = sum / (scores.length - 2);
        return avg;
    }
}
